package com.corechina.apex_osswords.controller;

import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.UpdatePwdDto;
import com.corechina.apex_osswords.domain.entity.SysUser;
import com.corechina.apex_osswords.service.ISysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: apex_osswords
 * @description: 用户管理访问控制类
 * @author: cc
 * @create: 2022-03-03 13:40
 **/

@Api(tags = "系统用户管理")
@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private ISysUser iSysUser;

    @ApiOperation("新增用户")
//    @RequiresPermissions("sys:user:add")
    @SysLog("新增用户")
    @PostMapping("/add")
    public Response add(@RequestBody SysUser sysUser) {
        return iSysUser.add(sysUser);
    }

    @ApiOperation("编辑用户信息")
    //    @RequiresPermissions("sys:user:update")
    @SysLog("编辑用户")
    @PutMapping("/update")
    public Response update(@RequestBody SysUser sysUser) {
        return iSysUser.update(sysUser);
    }

    @ApiOperation("获取详情")
//    @RequiresPermissions("sys:user:update")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iSysUser.getOne(id);
    }

    @ApiOperation("查询用户列表")
    //    @RequiresPermissions("sys:user:queryUserAllList")
    @GetMapping("/queryUserAllList")
    public Response queryUserAllList(String userName, Integer pageIndex, Integer pageSize) {
        return iSysUser.getUserAllList(userName, pageIndex, pageSize);
    }

    @ApiOperation("修改密码")
    @SysLog("修改用户密码")
    @PutMapping("/updatePwd")
    public Response updatePwd(@RequestBody UpdatePwdDto updatePwdDto){
        return iSysUser.updatePwd(updatePwdDto.getOldPwd(),updatePwdDto.getNewPwd());
    }

    @ApiOperation("重置密码")
//    @RequiresPermissions("sys:user:update")
    @SysLog("重置用户密码")
    @GetMapping("/resetPwd")
    public Response resetPwd(Integer id){
        return iSysUser.resetPwd(id,"Apex@1234");
    }

    @ApiOperation("删除")
    @SysLog("删除用户")
    @DeleteMapping("/del")
    public Response del(Integer id){
        return iSysUser.del(id);
    }
}
